# Maintainer: Thore Bödecker <foxxx0@archlinux.org>
# Contributor: wangjiezhe <wangjiezhe AT yandex DOT com>

_name=cheroot
pkgname=python-cheroot
pkgdesc="Highly-optimized, pure-python HTTP server"
pkgver=9.0.0
pkgrel=5
arch=('any')
url="https://github.com/cherrypy/cheroot"
license=('MIT')
depends=(
  'python-jaraco.functools'
  # NOTE: open ticket upstream about this missing
  python-jaraco.text  # undocumented, but required in cheroot/workers/threadpool.py
  'python-more-itertools'
  'python-six'
)
optdepends=(
  'python-pyopenssl: for SSL and certificate handling within cheroot'
)
makedepends=('python-build' 'python-installer' 'python-setuptools'
'python-setuptools-scm' 'python-wheel')
# TODO: package python-pytest-watch
# TODO: package python-pypytools
checkdepends=(python-apipkg python-chardet python-colorama
python-jaraco.context python-portend python-pyopenssl
python-pytest python-pytest-forked python-pytest-rerunfailures
python-pytest-sugar python-pytest-xdist python-requests-toolbelt
python-requests-unixsocket python-trustme python-urllib3 python-watchdog)
source=("https://files.pythonhosted.org/packages/source/${_name:0:1}/${_name}/${_name}-${pkgver}.tar.gz")
sha512sums=('86ea0dd2cb4cde25f86b489b1d0bb27e3e7c1ba5449759ccecaae689cdcb349b968fd0c8fb8bc8273deff5e32a078bf40f4342f0c5a1f53bb8d2b968f44a453b')
b2sums=('5f5dd172cfc8fdd1318b22fc27060444a34343b6b83bbda4bd40c16d7cb0568c356f5fd14b0a7cdc74895d6707077ec54fcae54fb29b0d16a7c06e2cd36b1ee7')

prepare() {
  cd $_name-$pkgver
  # remove the use of python-setuptools-scm-git-archive
  # TODO: change upstream (and bump their setuptools-scm use to >= 7.0.5)
  sed -e '/setuptools_scm_git_archive/d' -i pyproject.toml setup.cfg requirements/*
}

build() {
  # setuptools wont find version from git tag
  export SETUPTOOLS_SCM_PRETEND_VERSION="${pkgver}"

  cd ${_name}-${pkgver}
  python -m build --wheel --no-isolation
}

check() {
  cd ${_name}-${pkgver}
  # TODO: package remaining checkdepends and run pytest
  # pytest -vv -c /dev/null
}

package() {
  cd ${_name}-${pkgver}
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE.md -t "$pkgdir/usr/share/licenses/$pkgname/"

  # remove /test/ directory from package
  python_stdlib_basepath="$(python -c "from sysconfig import get_path; print(get_path('stdlib'))")"
  rm -rvf "${pkgdir}/${python_stdlib_basepath#/}/site-packages/${_name}"/{test,testing.py}
}

# vim:set ts=2 sw=2 et:
